package com.aliyeye.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @version V999
 * @package com.aliyeye.config
 * @description: 来自三年开发经验，月薪100k，大佬代码
 * @author: 痞子洋
 * @date: 2019/6/9 17:29
 */

/**
 * @Configuration 表名这个类是一个配置类，相当于beans
 * 通过EnableConfigurationProperties指定需要的配置属性类，然后初始化到IOC容器中。
 */
@Configuration
@EnableConfigurationProperties(value = DataSourceProperties2.class)
public class DatasourceConfig {
    /**
     * 相当于 <bean class="com.alibaba.druid.pool.DruidDataSource" id ="datasource2"></>
     * @param properties
     * @return
     */
   // @Bean
    public DataSource datasource2(DataSourceProperties2 properties) {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(properties.getUrl());
        datasource.setUsername(properties.getUsername());
        datasource.setPassword(properties.getPassword());
        datasource.setDriverClassName(properties.getDriverClassName());
        return datasource;
    }
}
